{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import json\n",
    "import numpy as np\n",
    "import os\n",
    "import pandas as pd\n",
    "import urllib2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "url = 'https://poloniex.com/public?command=returnChartData&currencyPair=USDT_BTC&start=1356998100&end=9999999999&period=300'\n",
    "openUrl = urllib2.urlopen(url)\n",
    "r = openUrl.read()\n",
    "openUrl.close()\n",
    "d = json.loads(r.decode())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Close</th>\n",
       "      <th>Timestamp</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424373000</td>\n",
       "      <td>0.33</td>\n",
       "      <td>225.0</td>\n",
       "      <td>0.33</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424373300</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424373600</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424373900</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424374200</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424374500</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424374800</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424375100</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424375400</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424375700</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424376000</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424376300</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424376600</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>225.0</td>\n",
       "      <td>1424376900</td>\n",
       "      <td>225.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>240.0</td>\n",
       "      <td>1424377200</td>\n",
       "      <td>240.00</td>\n",
       "      <td>225.0</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>240.0</td>\n",
       "      <td>1424377500</td>\n",
       "      <td>240.00</td>\n",
       "      <td>240.0</td>\n",
       "      <td>240.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>240.0</td>\n",
       "      <td>1424377800</td>\n",
       "      <td>240.00</td>\n",
       "      <td>240.0</td>\n",
       "      <td>240.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>240.0</td>\n",
       "      <td>1424378100</td>\n",
       "      <td>240.00</td>\n",
       "      <td>240.0</td>\n",
       "      <td>240.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>240.0</td>\n",
       "      <td>1424378400</td>\n",
       "      <td>240.00</td>\n",
       "      <td>240.0</td>\n",
       "      <td>240.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424378700</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424379000</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424379300</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424379600</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424379900</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424380200</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424380500</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424380800</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424381100</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424381400</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424381700</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424394000</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424394300</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424394600</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424394900</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424395200</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424395500</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>76</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424395800</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>77</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424396100</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>78</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424396400</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>79</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424396700</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>80</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424397000</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>81</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424397300</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424397600</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424397900</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>84</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424398200</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>85</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424398500</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>86</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424398800</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>87</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424399100</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>88</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424399400</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>89</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424399700</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>90</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424400000</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>91</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424400300</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>92</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424400600</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>93</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424400900</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>94</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424401200</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424401500</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424401800</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424402100</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424402400</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>244.0</td>\n",
       "      <td>1424402700</td>\n",
       "      <td>244.00</td>\n",
       "      <td>244.0</td>\n",
       "      <td>244.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    Close   Timestamp    High    Low    Open\n",
       "0   225.0  1424373000    0.33  225.0    0.33\n",
       "1   225.0  1424373300  225.00  225.0  225.00\n",
       "2   225.0  1424373600  225.00  225.0  225.00\n",
       "3   225.0  1424373900  225.00  225.0  225.00\n",
       "4   225.0  1424374200  225.00  225.0  225.00\n",
       "5   225.0  1424374500  225.00  225.0  225.00\n",
       "6   225.0  1424374800  225.00  225.0  225.00\n",
       "7   225.0  1424375100  225.00  225.0  225.00\n",
       "8   225.0  1424375400  225.00  225.0  225.00\n",
       "9   225.0  1424375700  225.00  225.0  225.00\n",
       "10  225.0  1424376000  225.00  225.0  225.00\n",
       "11  225.0  1424376300  225.00  225.0  225.00\n",
       "12  225.0  1424376600  225.00  225.0  225.00\n",
       "13  225.0  1424376900  225.00  225.0  225.00\n",
       "14  240.0  1424377200  240.00  225.0  225.00\n",
       "15  240.0  1424377500  240.00  240.0  240.00\n",
       "16  240.0  1424377800  240.00  240.0  240.00\n",
       "17  240.0  1424378100  240.00  240.0  240.00\n",
       "18  240.0  1424378400  240.00  240.0  240.00\n",
       "19  244.0  1424378700  244.00  244.0  244.00\n",
       "20  244.0  1424379000  244.00  244.0  244.00\n",
       "21  244.0  1424379300  244.00  244.0  244.00\n",
       "22  244.0  1424379600  244.00  244.0  244.00\n",
       "23  244.0  1424379900  244.00  244.0  244.00\n",
       "24  244.0  1424380200  244.00  244.0  244.00\n",
       "25  244.0  1424380500  244.00  244.0  244.00\n",
       "26  244.0  1424380800  244.00  244.0  244.00\n",
       "27  244.0  1424381100  244.00  244.0  244.00\n",
       "28  244.0  1424381400  244.00  244.0  244.00\n",
       "29  244.0  1424381700  244.00  244.0  244.00\n",
       "..    ...         ...     ...    ...     ...\n",
       "70  244.0  1424394000  244.00  244.0  244.00\n",
       "71  244.0  1424394300  244.00  244.0  244.00\n",
       "72  244.0  1424394600  244.00  244.0  244.00\n",
       "73  244.0  1424394900  244.00  244.0  244.00\n",
       "74  244.0  1424395200  244.00  244.0  244.00\n",
       "75  244.0  1424395500  244.00  244.0  244.00\n",
       "76  244.0  1424395800  244.00  244.0  244.00\n",
       "77  244.0  1424396100  244.00  244.0  244.00\n",
       "78  244.0  1424396400  244.00  244.0  244.00\n",
       "79  244.0  1424396700  244.00  244.0  244.00\n",
       "80  244.0  1424397000  244.00  244.0  244.00\n",
       "81  244.0  1424397300  244.00  244.0  244.00\n",
       "82  244.0  1424397600  244.00  244.0  244.00\n",
       "83  244.0  1424397900  244.00  244.0  244.00\n",
       "84  244.0  1424398200  244.00  244.0  244.00\n",
       "85  244.0  1424398500  244.00  244.0  244.00\n",
       "86  244.0  1424398800  244.00  244.0  244.00\n",
       "87  244.0  1424399100  244.00  244.0  244.00\n",
       "88  244.0  1424399400  244.00  244.0  244.00\n",
       "89  244.0  1424399700  244.00  244.0  244.00\n",
       "90  244.0  1424400000  244.00  244.0  244.00\n",
       "91  244.0  1424400300  244.00  244.0  244.00\n",
       "92  244.0  1424400600  244.00  244.0  244.00\n",
       "93  244.0  1424400900  244.00  244.0  244.00\n",
       "94  244.0  1424401200  244.00  244.0  244.00\n",
       "95  244.0  1424401500  244.00  244.0  244.00\n",
       "96  244.0  1424401800  244.00  244.0  244.00\n",
       "97  244.0  1424402100  244.00  244.0  244.00\n",
       "98  244.0  1424402400  244.00  244.0  244.00\n",
       "99  244.0  1424402700  244.00  244.0  244.00\n",
       "\n",
       "[100 rows x 5 columns]"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(d)\n",
    "original_columns=[u'close', u'date', u'high', u'low', u'open']\n",
    "new_columns = ['Close','Timestamp','High','Low','Open']\n",
    "df = df.loc[:,original_columns]\n",
    "df.columns = new_columns\n",
    "df.head(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df.to_csv('data/bitcoin2015to2017.csv',index=None)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
